package com.ymatou.app.api.service;

import org.json.JSONArray;
import org.json.JSONObject;

import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;

/**
 * 据主题Id获取商品Call FreeMaker Template自动生成代码
 */
public class TopicProductsCall extends YmatouBaseCall {
	private static String opurl = "api/Group/TopicProducts";

	public TopicProductsCall() {
		super(EnvSetup.getSystemUrl("api_app"), opurl, "GET", "PARAM");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept", "text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("Code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 */
	public String getBCode() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("BCode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 */
	public String getMsg() {
		String Msg = null;
		try {
			Msg = new JSONObject(getReturnData()).getString("Msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Msg;
	}

	/**
	 * 获取Data
	 * 
	 * @return Data
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			JSONObject jo = new JSONObject(getReturnData());
			Data = jo.getJSONObject("Data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	/**
	 * 获取ProductID
	 */
	public String getProductID() {
		String ProductID = null;
		try {
			JSONArray temp = (JSONArray) getData().get("ProductList");
			JSONObject temp2 = (JSONObject) temp.get(0);
			ProductID = temp2.get("ProductID").toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ProductID;
	}

	/**
	 * 获取ProductID
	 */
	public String getSequence() {
		String Sequence = null;
		try {
			JSONArray temp = (JSONArray) getData().get("ProductList");
			JSONObject temp2 = (JSONObject) temp.get(0);
			Sequence = temp2.get("ProductID").toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Sequence;
	}
}